<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
  <head>
    <title>${appname}</title>
	<%@include file="../meta.jsp"%>
	<script src="${ctx}/includes/jquery.js" type="text/javascript"></script>
	<script src="${ctx}/includes/jquery.form.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript" src="${ctx}/js/lhgdialog/lhgdialog.js"></script>
	<script src="${ctx}/js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	
	<script src="${ctx}/includes/jquery.validate.js" type="text/javascript"></script>
	
	<script type="text/javascript">
		$(function(){
			$("#task_add_form").validate({
				errorPlacement: function(error, element){
		            $(element).next('.field_notice').hide();
		            $(element).after(error);
		       },
			   success: function(label){   
			       label.addClass('right').text('OK!');
			   },
			   rules:   
			   {
			    	title : {required : true},
	            	lb : {required : true},
	            	zrr:{required : false},
	            	deptids:{required : true},
	            	jhwcsj:{required : true},
	            	zsbmlxr:{required : true},
	            	content: {required : true}
			   },   
			   message:{
			    	zt : {required : '请填写业联标题'},
	            	lb : {required : '请选择业联类别'},
	            	zrr:{required : '请选择审批人'},
	            	deptids:{required : '请选择主送部门'},
	            	jhwcsj:{required : '请选择完成时间'},
	            	zsbmlxr:{required : '请选输入主送部门联系人'},
	            	content : {required : '请填写业联内容'}
			   },
			   submitHandler: function() {
			   		addTask();
			   }
			});  
		});
	</script>
  </head>
  
  <body>
    <div class="Teg_body">
    	<%@include file="../header.jsp"%>
    	
    	<div class="Teg_content">
    		<div class="content_left i-pane" id="zhd_LeftPane" paneid="LeftPane">
    			<div class="m-second-menu-title">
	    			<span class="Head">我的业联</span>
    			</div>
    			<div class="m-second-menu-ct ZHDAlignleft">
	    			<div class="accordion-3-container">
	    				<ul class="accordion-3">
	    					<%@include file="task_left_menu.jsp"%>
	    				</ul>
	    			</div>
    			</div>
    			
    			<%@include file="../leftmenu.jsp"%>
    		</div>
    		<div class="content_right">
    			<div class="second_breadcrumb">
    				<span class="current_position">您的当前位置：<a href="${ctx}">首页</a>></span><span><a href="${ctx}/task_myTask.do" class="SkinObject">我的业联</a></span>
    			</div>
    			<div class="content_ct i-pane" id="zhd_ContentPane" style="margin-top: 5px;">
    				<s:form action="task_save.do" method="post" id="task_add_form" enctype="multipart/form-data"  onsubmit="return false;">
    				<s:token/>
    				<table class="form-table">
						<tr>
							<th width="150"><span class="note_red">*</span>业联标题：</th>
							<td>
							<s:textfield key="title" title="请填写业联标题" cssClass="form-txtinput" id="title" size="50" maxlength="100" value="%{model.title}"/>
							</td>
						</tr>
						<tr>
							<th width="150"><span class="note_red">*</span>业联类别：</th>
							<td>
							<mytag:select id="lb" title="请选择业联类别" name="lb" sql="basedata" isSql="false" condition="27" dataType="Long" listKey="id" listValue="name" headerKey="" headerValue="请选择" onchange="xzrwlb(this)"/>
							</td>
						</tr>
						<tr>
							<th width="150"><span class="note_red">*</span>业联内容：</th>
							<td>
							<textarea rows="15" name="content" title="请输入业联内容" id="content" style="width: 500px;"></textarea>
							</td>
						</tr>
						<tr>
							<th width="150"><span class="note_red">*</span>完成时间：</th>
							<td>
							<s:textfield name="jhwcsj" title="请输入完成时间" cssClass="form-txtinput" maxlength="20" value="%{model.jhwcsjString}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true"/>
							</td>
						</tr>
						<tr id="zc_spr">
							<th width="150"><span class="note_red">*</span>审批人：</th>
							<td>
							<s:hidden name="hanlder" id="zrrbh"/>
							<s:textfield name="zrr" title="请输入审批人" cssClass="form-txtinput" id="zrr" maxlength="20" value="%{model.hander}"/>
							</td>
						</tr>
						<tr style="display: none;" id="xmgl_spr">
							<th width="150"><span class="note_red">*</span>审批人：</th>
							<td>
							<mytag:select id="xmspr" title="请选择审批人" name="xmspr" sql="xmspr" isSql="false" listKey="userid" listValue="name" headerKey="" headerValue="请选择"/>
							</td>
						</tr>
						<tr>
							<th width="150"><span class="note_red">*</span>主送部门：</th>
							<td>
								<select multiple="multiple" size="1" id="depts" title="请选择主送部门" name="deptids" style="width: 120px;;border:1px solid #DAE0E5;height:30px;"></select>
								<span>
								<a class="btn_short" href="javascript:void(0)" title="添加部门" name="btn_addDepts" id="btn_Depts"
									onClick="selectDept()">选择</a>
								<a class="btn_short" href="javascript:void(0)" title="删除部门" name="btn_delDepts" id="btn_delDepts" 
								    onClick="deleteDept('depts');">删除</a>
								</span>
							</td>
						</tr>
						<tr>
							<th width="150"><span class="note_red">*</span>主送部门联系人：</th>
							<td>
							<s:textfield name="zsbmlxr" title="请输入主送部门联系人" cssClass="form-txtinput" maxlength="20" value="%{model.zsbmlxr}" />
							</td>
						</tr>
						<tr>
							<th width="150">抄送部门：</th>
							<td>
								<select multiple="multiple" size="4" id="senddepts" title="请选择抄送部门" name="sendDeptids" style="width: 120px;;border:1px solid #DAE0E5;height:100px;"></select>
								<span>
								<a class="btn_short" href="javascript:void(0)" title="添加部门" name="btn_addDepts" id="btn_Depts"
									onClick="selectSendDept()">选择</a>
								<a class="btn_short" href="javascript:void(0)" title="删除部门" name="btn_delDepts" id="btn_delDepts" 
								    onClick="deleteDept('senddepts');">删除</a>
								</span>
							</td>
						</tr>
						<tr>
							<th width="150">附件：</th>
							<td id="files">
							<input type="button" onclick="addComponent();" value="添加文件" /> <br/>
							<input name="attachFiles" type="file" size="50"/><br/><br/>
							</td>
						</tr>
					</table>
					<div class="win-btn-panel">
						<input class="btn-short" type="submit" value=" 提 交 " title="点击提交" id="sub_btn">
					</div>
					
    				</s:form>
    			</div>
    		</div>
    		<div class="clear"></div>
    		<div class="output1"></div>
    	</div>
    	<%@include file="../bottom.jsp"%>
    </div>
  </body>
</html>
<script type="text/javascript">
function xzrwlb(A){
	if(A.value == 160){
		$('#xmgl_spr').removeAttr('style');
		$('#zc_spr').attr('style','display:none');
	}else{
		$('#xmgl_spr').attr('style','display:none');
		$('#zc_spr').removeAttr('style');
	}
}
function addComponent(){
	var tid = new Date().getTime();
	var str = "<div id='"+tid+"'><input type='file' name='attachFiles'  size='50'/><input type='button' value='删除' onclick='delUpFile("+tid+")'/></div>";
	$('#files').append(str);
}
function delUpFile(tid){
	$('#'+tid).remove();
}
function addTask(){
	var lb = $('#lb').val();
	if(lb == 160){
		var xmspr = $('#xmspr').val();
		if(xmspr == ''){alert('请选择审批人!');return false;}
	}else{
		var xmspr = $('#zrrbh').val();
		if(xmspr == ''){alert('请选择审批人!');return false;}
	}
	
	var selectObj = document.getElementById("depts");
	var selectOptions = selectObj.options;
	if (selectOptions == null || selectOptions.length == 0){
		return;
	}else{
		for (var i=0;i<selectOptions.length;i++){
			selectObj[i].selected = true;
		}
	}
	
	var selectObj2 = document.getElementById("senddepts");
	var selectOptions2 = selectObj2.options;
	if (selectOptions2 == null || selectOptions2.length == 0){
		
	}else{
		for (var i=0;i<selectOptions2.length;i++){
			selectObj2[i].selected = true;
		}
	}
	var v = $("#task_add_form").valid();
	if(!v)return false;
	//var seldept = document.getElementById("depts").value;
	
    $('#task_add_form').ajaxSubmit(resultHandler);
    return false;
}
function resultHandler(responseXML){
	var result = responseXML.getElementsByTagName("result")[0].firstChild.nodeValue;
	var message = responseXML.getElementsByTagName("error-message")[0].firstChild.nodeValue;
	var errorType = responseXML.getElementsByTagName("error-type")[0].firstChild.nodeValue;
	if(!eval(result)&&(errorType!=2))
	{
		confirmDialog({content:message,closeCallback:function(){window.location.reload();}});
	}
	else
	{
		var curDate = new Date(); 
		alert(message);
		location.replace("${ctx}/task_create.do?opt=createtask&timsStamp=" + curDate.getTime());
	}
}

$('#zrr').click(function(){
	$.dialog({
	  	id:'abc', 
	  	title:'选择人员', 
	  	content: 'url:${ctx}/pub/userByDeptSelect.jsp?timestamp='+new Date().getTime(), 
	  	max:false,
	  	min:false,
	  	width:600, 
	  	height:450,
	  	ok: function(){ 
	       	var m = abc.selectOnlyUser();
	        return m; 
	    }, 
	    cancelVal: '关闭', 
	    cancel: true
  	});
});

function selectDept(){
  $.dialog({
  	id:'abc', 
  	name:'abc',
  	title:'选择部门', 
  	content: 'url:${ctx}/pub/userAllTopDeptSelect.jsp?timestamp='+new Date().getTime(), 
  	max:false,
  	min:false,
  	width:600, 
  	height:450,
  	ok: function(){ 
       	var m = abc.selectOneDept();
       	if(m){
        	return true; 
        }else{
        	return false;
        }
    }, 
    cancelVal: '关闭', 
    cancel: true
  });
}

function selectSendDept(){
  $.dialog({
  	id:'abc', 
  	name:'abc',
  	title:'选择部门', 
  	content: 'url:${ctx}/pub/userAllTopDeptSelect.jsp?timestamp='+new Date().getTime(), 
  	max:false,
  	min:false,
  	width:600, 
  	height:450,
  	ok: function(){ 
       	var m = abc.selectMoreSendDept();
       	return true;
    }, 
    cancelVal: '关闭', 
    cancel: true
  });
}

function deleteDept(A){
	var selectObj = document.getElementById(A);
	var selectOptions = selectObj.options;
	if (selectOptions == null || selectOptions.length == 0 || selectOptions.selectedIndex == -1){
		var msg="请先选择要删除的部门！";
		alert(msg);
		return;
	}
	var ilen=selectOptions.length;
	for (var i=ilen-1; i>=0; i--){
		if(selectObj[i].selected)
		    selectObj.remove(i);
	}
}
</script>